﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using B10.Models.Validation;

namespace B10.Models
{
    public class UserPageFormViewModel
    {
        public UserPage Page { get; private set; }
        //public SelectList Categories { get; private set; }        
        public MultiSelectList CategoriesList { get; private set; }
        [LocalizedDisplayName("Category")]
        public int[] SelectedCategories { get; set; }

        public UserPageFormViewModel(UserPage page)
        {
            Page = page;
            
            CategoriesList = GetCategories(page);
            //Categories = new SelectList(CategoryHelper.GetCategories(), "Id", "Name", (int)page.Category);
        }

        private MultiSelectList GetCategories(UserPage page)
        {
            List<int> selected = new List<int>();
            selected.Add((int)page.Category);
            if (page.Category2.HasValue)
                selected.Add((int)page.Category2.Value);
            if (page.Category3.HasValue)
                selected.Add((int)page.Category3.Value);
            return new MultiSelectList(CategoryHelper.GetCategories(), "Id", "Name", selected);
        }
    }
}
